package neiltwist.graphics;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;

public class WindowImpl {
	
	 /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
//    private static void createAndShowGUI() {
	public static void main(String[] args) {
        //Create and set up the window.
        JFrame frame = new JFrame("NCFD");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
        Image image = new Image();
        
        frame.setPreferredSize(new Dimension(512, 512));
        frame.getContentPane().add(image, BorderLayout.CENTER);
        
//        frame.add(new Image());
 
        //Display the window.
        frame.pack();
        frame.setVisible(true);
        
        
        int frames = 51;
        
        /**
         *  Loop through some shit
         */
        long frameTime = 0;
        long startTime = System.currentTimeMillis();
        
        for (int t=1 ; t<frames; t++){
//        while(true) {
        	long frameStartTime = System.currentTimeMillis();
        	for (int x=0 ; x<512; x++){
        		for (int y=0 ; y<512; y++){
        			image.process(x,y,0);
//        			System.out.println(x+" "+y);
        		}
        	}
        	frame.repaint();
        	
        	long frameEndTime = System.currentTimeMillis();
        	
        	frameTime += (frameEndTime - frameStartTime);
        }
        
        long endTime = System.currentTimeMillis();
        
        long timeTaken = endTime - startTime;
        
        System.out.println("average frame time = " + (frameTime / frames));
        System.out.println(String.format("frame rate = %f, calcd from %d %d",(frames / (timeTaken / 1000)),frames, timeTaken));
    }
 
//    public static void main(String[] args) {
//        //Schedule a job for the event-dispatching thread:
//        //creating and showing this application's GUI.
//        javax.swing.SwingUtilities.invokeLater(new Runnable() {
//            public void run() {
//                createAndShowGUI();
//            }
//        });
//    }

}
